window.onbeforeunload =  function(){
	var fage = false;
  	var id = '';
  	var t_id = '' ;
	var d_id = '' ;
	
	if ( $('#ar_id').length > 0 ) { //文章
		id = $('#ar_id').val();
		fage = true;
	} 
	else if ( $('#ws_id').length > 0 ) {   //产品
		id = $('#ws_id').val();
		fage = true;
	} else if( $("input[name='TID']").val() > 0 && $("input[name='D_ID']").val() > 0 ){	//模版
		d_id = $("input[name='D_ID']").val();
		t_id = $("input[name='TID']").val() ;
		fage = true ;
	}
	
	
	
	
	if (fage) {
		
		var url = location.href;
		
		$.ajax({
			async:false, 
			url:'/wondershare/task_queue.php?action=delete', 
			data:{'id':id, 'url':url , 'd_id':d_id , 't_id':t_id}, 
			success:function(data)
			{
				result = true;
			}
		});
	}

}


//删除队列
function  deleteInfo(id, type, act_type) {
	
	var str = "";
	var tips = '确定删除记录吗?';
	var falge = false;
	
	if (type == 'moreDel') {
		
		var decollator = '';
		$('input[name="ID[]"]').each(function () 
		{
			if ($(this).attr('checked'))  {
				
				falge = true; 
				str += decollator + $(this).val();
				decollator = ',';
			}
		});

		if ( !falge ) {
			alert('你没有选择任何选项！');  
			return false;
		}
	
	} else {
		str = id; 
	}
	
	if ( confirm(tips) ) { 
	
		var result = false;
		if (act_type == 'task_queue') {//删除队列
			
			$.ajax({
				async:false, 
				url:'/wondershare/task_queue.php?action=delete', 
				data:{str_qid:str}, 
				success:function(data)
				{
					alert(data);
					result = true;
				}
			});

		} else if (act_type == 'task_site') {//删除站点
			
			$.ajax({
				async:false, 
				url:'/wondershare/task_site.php?action=delete', 
				data:{str_site_id:str}, 
				success:function(data)
				{
					alert(data);
					result = true;
				}
			});

		} else if (act_type == 'task_manage') {//删除我的任务
			
			$.ajax({
				async:false, 
				url:'/wondershare/task_manage.php?action=ajaxTask', 
				data:{str_manage_id:str, 'type': $("#type").val(), action_type : 'delete'}, 
				success:function(data)
				{
					alert(data);
					result = true;
				}
			});

		}  else if (act_type == 'task_server') {//删除服务器信息
			
			$.ajax({
				async:false, 
				url:'/wondershare/task_server.php?action=delete', 
				data:{str_ser_id:str, action_type : 'delete'}, 
				success:function(data)
				{
					alert(data);
					result = true;
				}
			});

		} 
		
		if (result) {
			
			if (type != 'moreDel') {
				$("#tr_"+id).remove();
				$('#total').html(parseInt($('#total').html())-1) ;
			} else {
				$('input[name="ID[]"]').each(function () {
					if ($(this).attr('checked'))  {
						$("#tr_"+$(this).val()).remove();
						$('#total').html(parseInt($('#total').html())-1) ;
					}
				}); 
			}
		}

	}
}


//修改任务状态
function updateTaskState(mId, state, type) {
	
	var PubAid = state == 3 ? $("#PubAid").val() : '';
	
	$.ajax({
			async:false, 
			url:'/wondershare/task_manage.php?action=ajaxTask', 
			data:{state:state, mId:mId, action_type:'update_state', type:type, PubAid: PubAid}, 
			success:function(data)
			{
				alert(data);
				window.location.href  = window.location.href;
			}
		});
}

//验证ip
function isIP(strIP) { 

	var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g //匹配IP地址的正则表达式 
	if (re.test(strIP))  { 
		if( RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256) return true; 
	} 
	return false; 
}


//确认选择简单弹出框操作
function confirmSimpleSelect(checkbox_name, input_name, hide_input_name, cvbox_id) {
	
	
	var str_id = "";
	
	var c = '';
	$('input[name="'+checkbox_name+'[]"]').each(function () {
		if ($(this).attr('checked'))  {
			str_id += c + $(this).val() ;
			c = ','
		}
	});
	
	
	if (typeof(str_id) == 'undefined') {
		str_id = '';
	}

	$("#"+input_name).val(str_id);
	$("#"+hide_input_name).val(str_id);
	$("#cvBoxTitleBarClose").click();
  	$("#"+cvbox_id).hide();
 

}


//显示弹出对话框
function showCvbox(operation_type, id, title) {
	

	if ( operation_type == 'select_server' ) {
		
		$("#"+id).show();
		$("#"+id).cvbox({
			titleBarText: title
		});
		
	}
}

//获取任务相应的文件路径
function getTaskFileInfo(sId, IsFtp){
	var fage = false;
	
	$.ajax({
			async:false, 
			url:'/wondershare/task_manage.php?action=ajaxTask', 
			data:{sId:sId, IsFtp:IsFtp, action_type:'get_task_file', type:'self'}, 
			dataType:'json',
			success:function(data)
			{
				if (data.msg != '' && data.is_create == 1) {//木有创建该网站任务
					if ( confirm(data.msg) ) {
						window.location.href  = '/wondershare/task_manage.php?action=editData&type=self&sId='+sId+'&IsFtp='+IsFtp;
					}
				} else if (data.msg != '' && data.is_create == 0) {//已经创建任务，但是该网站任务不是未测试状态。
					if ( confirm(data.msg) ) {
						window.location.href  = '/wondershare/task_manage.php?type=self';
					}
				} else if (data.msg == '' && data.is_create == 0) {//已经创建任务，但是该网站任务是未测试状态。
					
					$("#mEditFile").val(data.mEditFile);
					$("#mDeleteFile").val(data.mDeleteFile);
					$("#mCdnEditFile").val(data.mCdnEditFile);
					$("#mCdnDeleteFile").val(data.mCdnDeleteFile);
					$("#mEditFile1").val(data.mEditFile);
					$("#mDeleteFile1").val(data.mDeleteFile);
					$("#mCdnEditFile1").val(data.mCdnEditFile);
					$("#mCdnDeleteFile1").val(data.mCdnDeleteFile);
					
					fage = true;
				}
				
			}
		});
		
		return fage;
}

//获取发布任务
function taskPub(id, operation_type, type) {
	
	if ( confirm('确定要发布你所选择的吗？') ) { 
	
		var mId_str = '';//任务ID
		if (operation_type == 'morePub') {
				
			var decollator = '';
			$('input[name="ID[]"]').each(function () 
			{
				if ($(this).attr('checked'))  {
					
					falge = true; 
					mId_str += decollator + $(this).val();
					decollator = ',';
				}
			});
	
			if ( !falge ) {
				alert('你没有选择任何选项！');  
				return false;
			}
		
		} else {
			mId_str = id; 
		}

		window.location.href = '/wondershare/task_pub.php?action=pub&type='+type+'&mId_str='+mId_str;
		
	}
}
